package com.example;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ScheduleDAO {

    public List<Schedule> getSchedulesByStudentUsername(String studentUsername) {
        List<Schedule> schedules = new ArrayList<>();
        String sql = "SELECT id, studentUsername, courseName, dayOfWeek, startTime, endTime, location, teacherName, semester FROM schedules WHERE studentUsername = ?";

        try (Connection conn = DatabaseUtil.getConnection();
             PreparedStatement pstmt = conn.prepareStatement(sql)) {

            pstmt.setString(1, studentUsername);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                Schedule schedule = new Schedule(
                    rs.getInt("id"),
                    rs.getString("studentUsername"),
                    rs.getString("courseName"),
                    rs.getString("dayOfWeek"),
                    rs.getString("startTime"),
                    rs.getString("endTime"),
                    rs.getString("location"),
                    rs.getString("teacherName"),
                    rs.getString("semester")
                );
                schedules.add(schedule);
            }
        } catch (SQLException e) {
            System.err.println("Error fetching schedules for student " + studentUsername + ": " + e.getMessage());
        }
        return schedules;
    }
} 